<?php
namespace Home\Controller;
use Think\Controller;
class LyController extends Controller {
    public function index(){
        $appname='留言板';
        $this->assign('appname',$appname);//应用名称
        $ly=M('Ly');
        $count = $ly->count();
        $page = new \Think\Page($count, 5);
        //$page=new Page($count,8);//每页显示条数
        $page->setConfig('first', '首页');
        $page->setConfig('prev', '上一页');
        $page->setConfig('current', '当前');
        $page->setConfig('next', '下一页');
        $page->setConfig('end', '末页');
        $page->setConfig('theme', ' %FIRST% %UP_PAGE% 第 %NOW_PAGE%页 %DOWN_PAGE% %END%');
        $page->rollPage = 3;
        $show = $page->show();
        $list = $ly
            ->limit($page->firstRow, $page->listRows)
            ->order('id desc')
            ->select();
        $this->assign('page',$show);
        $this->assign('ly',$list);
        $this->display();
    }
    public function doly(){
        if(empty($_POST['name'])or empty($_POST['content'])){
            $this->error('姓名和内容不能为空！');
        }
        $data=array(
            name=>I('post.name'),
            qq=>I('post.qq'),
            content=>I('post.content'),
            time=>time()
        );
        $ly=M('Ly');
        $doly=$ly->add($data);
        if($doly){
            $this->success('留言成功',U('index'));
        }
    }
}